Page({
  data: {
    cardCur: 0,
    distance: 0,
    isShow: false,
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/JL/JL1.jpg'
    }, {
      id: 1,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/JL/JL2.jpg'
    }, {
      id: 2,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/JL/JL3.jpg'
    }, {
      id: 3,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/JL/JL4.jpg'
    }, {
      id: 4,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/JL/JL5.jpg'
    }, {
      id: 5,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/JL/JL6.jpg'
    }, {
      id: 6,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/JL/JL7.jpg'
    }],
    swiperList1: [{
      id: 0,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/PPT/PPT1.jpg'
    }, {
      id: 1,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/PPT/PPT2.jpg'
    }, {
      id: 2,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/PPT/PPT3.jpg'
    }, {
      id: 3,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/PPT/PPT4.jpg'
    }, {
      id: 4,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/PPT/PPT5.jpg'
    },
    {
      id: 5,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/PPT/PPT6.jpg'
    }, {
      id: 6,
      type: 'image',
      url: 'https://xwx.gzzmedu.com:6899/resource/PPT/PPT7.jpg'
    }]
  },
  onShareAppMessage (options) {
    // https://xwx.gzzmedu.com:6899/pic/share.jpeg
    wx.navigateTo({
      url: '/pages/aShare/index'
    })
    return {
      title: '快来领取大礼包~',
      path: '/pages/aResume/index?redirect=/pages/aResume/index',
      imageUrl: 'https://xwx.gzzmedu.com:6899/pic/share.jpeg'
    }
  },
  createPic () {
    wx.showLoading({
      title: '正在生成',
    })
    wx.downloadFile({
      url: 'https://xwx.gzzmedu.com:6899/pic/share.jpeg',
      success: (res) => {
        if (res.statusCode === 200) {
          let img = res.tempFilePath
          wx.saveImageToPhotosAlbum({
            filePath: img,
            success: (res) => {
              wx.showToast({
                title: '保存成功',
                icon: 'success',
                duration: 2000
              })
              console.log(res)
            },
            fail: (err) => {
              wx.showToast({
                title: '生成失败',
                icon: 'none',
                duration: 2000
              })
              console.log(err)
            }
          })
        }
      },
      complete: () => {
        wx.hideLoading()
      }
    })
  },
  getResumeBlackList () {
    wx.showNavigationBarLoading()
    wx.$API['activityPage/getResumeBlackList']({}).then((result) => {
      wx.hideNavigationBarLoading()
      const { boolean } = result
      if (boolean) {
        // 跳首页
        wx.reLaunch({
          url: '/pages/home/index'
        })
      } else {
        this.setData({
          isShow: true
        })
      }
    }).catch((err) => {
      console.log(err)
      wx.hideNavigationBarLoading()
    })
  },
  onLoad (options) {
    this.getResumeBlackList()
    this.towerSwiper('swiperList');
    this.towerSwiper('swiperList1');
    // 初始化towerSwiper 传已有的数组名即可
  },
  DotStyle (e) {
    this.setData({
      DotStyle: e.detail.value
    })
  },
  // cardSwiper
  cardSwiper (e) {
    this.setData({
      cardCur: e.detail.current
    })
  },
  // towerSwiper
  // 初始化towerSwiper
  towerSwiper (name) {
    let list = this.data[name];
    for (let i = 0; i < list.length; i++) {
      list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2))
      list[i].mLeft = i - parseInt(list.length / 2)
    }
    this.setData({
      [name]: list
    })
  },
  // towerSwiper触摸开始
  towerStart (e) {
    this.setData({
      towerStart: e.touches[0].pageX,
      distance: 0
    })
  },
  // towerSwiper计算方向
  towerMove (e) {
    const distance = e.touches[0].pageX - this.data.towerStart
    this.setData({
      direction: distance > 0 ? 'right' : 'left',
      distance: Math.abs(distance)
    })
  },
  // towerSwiper计算滚动
  towerEnd (e) {
    if (this.data.distance < 30) return
    let name = e.currentTarget.dataset.name
    let direction = this.data.direction;
    let list = this.data[name];
    if (direction == 'right') {
      let mLeft = list[0].mLeft;
      let zIndex = list[0].zIndex;
      for (let i = 1; i < list.length; i++) {
        list[i - 1].mLeft = list[i].mLeft
        list[i - 1].zIndex = list[i].zIndex
      }
      list[list.length - 1].mLeft = mLeft;
      list[list.length - 1].zIndex = zIndex;
      this.setData({
        [name]: list
      })
    } else {
      let mLeft = list[list.length - 1].mLeft;
      let zIndex = list[list.length - 1].zIndex;
      for (let i = list.length - 1; i > 0; i--) {
        list[i].mLeft = list[i - 1].mLeft
        list[i].zIndex = list[i - 1].zIndex
      }
      list[0].mLeft = mLeft;
      list[0].zIndex = zIndex;
      this.setData({
        [name]: list
      })
    }
  }
})